export default {
  namespace: 'listView',
  subscriptions: {
    setup ({ dispatch, history }) {
      history.listen((location) => {
        // 用户刷新页面时候请求编排接口
        if (location.pathname === '/listView') {
          dispatch({
            type:'dataAction'
          })
        }
      })
    }
  },
  state: {
    data:[
      {
        img: 'https://zos.alipayobjects.com/rmsportal/dKbkpPXKfvZzWCM.png',
        title: 'Meet hotel',
        des: '不是所有的兼职汪都需要风吹日晒'
      },
      {
        img: 'https://zos.alipayobjects.com/rmsportal/XmwCzSeJiqpkuMB.png',
        title: "McDonald's invites you",
        des: '不是所有的兼职汪都需要风吹日晒'
      },
      {
        img: 'https://zos.alipayobjects.com/rmsportal/hfVtzEhPzTUewPm.png',
        title: 'Eat the week',
        des: '不是所有的兼职汪都需要风吹日晒'
      },{
        img: 'https://zos.alipayobjects.com/rmsportal/XmwCzSeJiqpkuMB.png',
        title: "McDonald's invites you",
        des: '不是所有的兼职汪都需要风吹日晒'
      },
      {
        img: 'https://zos.alipayobjects.com/rmsportal/hfVtzEhPzTUewPm.png',
        title: 'Eat the week',
        des: '不是所有的兼职汪都需要风吹日晒'
      }
    ]
  },
  effects:{
    * dataAction ({ payload },{ put , select}) {
      console.log(1)
      let num = 5
      const data = yield select(state => {
        return state.listView.data
      })
      let index = data.length - 1
      for (let i = 0; i < num; i++) {
        console.log(data)
        if (index < 0 ) {
          index = data.length - 1
        } else {
          console.log(index)
          data.push(data[index])
          index--
        }
      }
      console.log(data)
      yield put({
        type: 'changeData',
        payload: {
          data
        }
      })
    }
  },
  reducers: {
    changeData (state, { payload }) {
      console.log(`fuck`)
      return {
        state,
        ...payload
      }
    }
  }
}